home *** CD-ROM | disk | FTP | other *** search
/ C# & Game Programming - A…er's Guide (2nd Edition) / Buono 2nd Ed.iso / Chapter2 / 2.36 / 2.36.cs next >
Encoding:
Text File  |  2004-11-09  |  1.3 KB  |  42 lines

  1. /* Returning values. */
  2. using System;
  3.  
  4. namespace Chapter2 {
  5.     class Class1 {
  6.         static void Main() {
  7.             string input; 
  8.             int iNumberOne = 0, iNumberTwo = 0; // Local variables 
  9.     
  10.             iNumberTwo = RandomNumber();    
  11.         
  12.             while (iNumberOne != 99) { // 99 ends loop 
  13.                 Console.Write ("\n Guess the number, hint: "
  14.                     + "it's between ten and three.\n" 
  15.                     + "Can you guess it he, he, he? ");
  16.                 input = Console.ReadLine();
  17.                 iNumberOne = int.Parse(input);    
  18.  
  19.                 if (iNumberOne == iNumberTwo) {
  20.                     Console.WriteLine("\n Hey you win, with a smile "
  21.                         + "with a grin!!!");
  22.                     iNumberTwo = RandomNumber();
  23.                 } else if (iNumberOne > iNumberTwo) {
  24.                     Console.WriteLine("\n Too high smart guy!");
  25.                     iNumberTwo++; 
  26.                 } else {
  27.                     Console.WriteLine("\n Too low slow Joe");
  28.                     iNumberTwo--; 
  29.                 }      
  30.             }     
  31.         } 
  32.  
  33.         static int RandomNumber() {
  34.             Random rnd = new Random();
  35.             int n2 = (int)Math.Round(rnd.NextDouble() * 9) + 1;
  36.  
  37.             return (n2);   
  38.         } 
  39.     } 
  40. }
  41.  
  42.